package com.pda.xinma.presenter;

import com.pda.xinma.bean.EndFaceDetailBean;
import com.pda.xinma.bean.LatheMachinBean;
import com.pda.xinma.bean.ProcessBean;
import com.pda.xinma.bean.UserBean;
import com.pda.xinma.bean.request.ManMadeRequest;
import com.pda.xinma.contract.EndFaceDetailContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class EndFaceDetailPresenter extends BasePresenter<EndFaceDetailContract.View> implements EndFaceDetailContract.Presenter {
    @Override
    public void selectDeliveryDetail(String orderNo) {
        NetUtils.geApi().selectDeliveryDetail(orderNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<EndFaceDetailBean>>() {
                    @Override
                    public void accept(BaseAppEntity<EndFaceDetailBean> endFaceDetailBeanBaseAppEntity) throws Exception {
                        getView().setData(endFaceDetailBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
    @Override
    public void getLatheListByCenter(String centerCode) {
        NetUtils.geApi().getLatheListByCenter(centerCode)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<LatheMachinBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<LatheMachinBean>> listBaseAppEntity) throws Exception {
                        getView().setLatheList(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getProcessByOrder(String orderNo, String centerCode) {
        NetUtils.geApi().getProcessByOrder(orderNo, centerCode)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<ProcessBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<ProcessBean>> listBaseAppEntity) throws Exception {
                        getView().setProcessList(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void confirmArtificialDelivery(ManMadeRequest request) {
        NetUtils.geApi().confirmArtificialDelivery(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<UserBean>>() {
                    @Override
                    public void accept(BaseAppEntity<UserBean> userBeanBaseAppEntity) throws Exception {
                        getView().showMessage(userBeanBaseAppEntity.getMessage());
                        getView().finishActivity();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
